import request from './request';

// 用户登录
export const wxLogin = (code) => {
  return request({
    url: '/user/login',
    method: 'POST',
    data: { code }
  });
};

// 退出登录
export const logout = () => {
  return request({
    url: '/user/logout',
    method: 'POST'
  });
};

// 根据id获取用户信息
export const getUserInfoById = (id) => {
  return request({
    url: '/user/getUserInfoById',
    method: 'POST',
    data: { id }
  });
};

// 修改用户信息
export const updateUserInfo = (data) => {
  return request({
    url: '/user/update',
    method: 'POST',
    data
  });
};

// AI识别书籍
export const identifyBookByAI = (urls) => {
  return request({
    url: '/book/identifyBookByAI',
    method: 'POST',
    data: {
      images: urls
    }
  });
};

// 上传书籍信息
export const uploadBookInfo = (data) => {
  return request({
    url: '/book/uploadBookInfo',
    method: 'POST',
    data
  });
};

// 修改书籍信息
export const updateBookInfo = (data) => {
  return request({
    url: '/book/updateBookInfo',
    method: 'POST',
    data
  });
};

// 删除书籍信息
export const deleteBookInfo = (id) => {
  return request({
    url: '/book/deleteBookInfo',
    method: 'POST',
    data: { id }
  });
};

// 分页查询书籍信息
export const getBookInfo = (params) => {
  return request({
    url: '/book/getBookInfo',
    method: 'POST',
    data: params
  });
};

// 获取书籍详细信息
export const getBookDetail = (id) => {
  return request({
    url: '/book/getBookDetail',
    method: 'POST',
    data: { id }
  });
};

// 搜索书籍
export const searchBook = (params) => {
  return request({
    url: '/book/searchBook',
    method: 'POST',
    data: params
  });
};

// 获取所有父分类
export const getAllParentCategory = () => {
  return request({
    url: '/category/getAllParentCategory',
    method: 'POST'
  });
};

// 根据父分类id获取子分类
export const getSubCategoryByParentId = (id) => {
  return request({
    url: '/category/getSubCategoryByParentId',
    method: 'POST',
    data: { id }
  });
};

// 获取当前用户的借阅记录（分页查询）
export const getMyRecord = (params) => {
  return request({
    url: '/borrowRecord/getMyRecord',
    method: 'POST',
    data: params
  });
};

// 创建借阅记录
export const addBorrowRecord = (data) => {
  return request({
    url: '/borrowRecord/addBorrowRecord',
    method: 'POST',
    data
  });
};

// 审核记录
export const auditRecord = (data) => {
  return request({
    url: '/borrowRecord/restoredRecord',
    method: 'POST',
    data
  });
};

//删除借阅记录
export const deleteRecord = (id) => {
  return request({
    url: `/borrowRecord/delete/${id}`,
    method: 'DELETE',
  });
};


// 文件上传
export const upLoadFile = (formData) => {
  return request({
    url: '/other/fileUpload',
    method: 'POST',
    data: formData,
    header: {
      'Content-Type': 'multipart/form-data'
    }
  });
};